package com.idea.zd.sys.util.word;

import com.idea.zd.sys.util.DateUtil;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zzy
 * @Date 2019-05-10 16:59
 */
public class Test {

    public static void main(String[] args) {
        File file = new File(System.getProperty("user.dir")+"/src/main/resources/template/保障燃烟计划申请表.docx");

        //替换的文本
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("previewTitle", "替previewTitle换");
        data.put("acceptUnit", "替acceptUnit换");
        data.put("workDate", DateUtil.getCurrentDate());

        List<String[]> list = new ArrayList<String[]>();

        list.add(new String[]{"1","2","3","4","5","6","7"});
        list.add(new String[]{"1","2","3","4","5","6","7"});






        try {
            WordTemplateHelper doc = new WordTemplateHelper(file);
            //替换
            doc.replaceTag(data);

            //插入表格行
            WordToNewWordUtils.changeTable(doc.getDocument(),list,2);
            //行合并
            WordToNewWordUtils.mergeCellVertically(doc.getDocument().getTables().get(0),0,2,3);

            FileOutputStream outputStream = new FileOutputStream(System.getProperty("user.dir")+"/src/main/resources/template/保障燃烟计划申请表_test.docx");



            doc.write(outputStream);

        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
